<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
	Class Name	: zetro_form
	Purpose		: Auto generate form 
	Author		: Iswan Putera S.Kom
	Date		: March 2013
	Version		: 1.0.0
*/
class zetro_form extends zetro_manager
{
	function __construct()
	{
		parent::__construct();
		$this->CI=& get_instance();
		$this->CI->load->library('zetro_auth');
	}
	function active_user($userid='')
	{
		return $this->userid=$userid;
	}
	
	function frm_file($path='')
	{
		$this->path=$path;	
	}
	function section($sec='',$sec2='',$sec3='')
	{
		$this->sec=$sec;
		$this->sec2=($sec2!='')?$sec2:'';
		$this->sec3=($sec3!='')?$sec3:'';
	}
	//generate standard form
	function frm_std($id='frm1',$width='40%',$adfrm=false,$tp='frm')
	{
		$row=0;$data='';
		$row=$this->Count($this->sec,$this->path);
		$data="<form id='".$id."' name='".$id."' method='post' action='' class='form-horizontal'>";
		for($i=1;$i<=$row;$i++)
		{
			$rContent=$this->rContent($this->sec,$i,$this->path);
			$caption=explode(',',$rContent);
			$this->field_type($rContent);
			$data.="<div class='control-group' id='g_".$caption[3]."'>";
			$data.="<label class='control-label' for='".$caption[3]."'>".$caption[0]."</label>";
			$data.="<div class='controls' style='width:".$width."'>";
			$data.=$this->field."";
			$data.="</div><div class='controls'></div></div>";
		}
		$data.=($adfrm==true && $tp=='frm')?$this->frm_insert():'';
		$data.=($adfrm==true && $tp!='frm')?$this->frm_gabungan():'';
 		$data.=empty($this->button)?$this->buttone:$this->button;
		if(!empty($this->AddField))
		{
			$data.=(!empty($this->dp_Modal) && $this->dp_Modal==$id)?$this->AddField:'';
		}
		$data.="</form>";
	   	return $data;
	}
	function frm_insert()
	{
		$row=0;$data='';
		$row=$this->Count($this->sec2,$this->path);
		for($i=1;$i<=$row;$i++)
		{
			$rContent=$this->rContent($this->sec2,$i,$this->path);
			$caption=explode(',',$rContent);
			$this->field_type($rContent);
			$data.="<div class='control-group' id='g_".$caption[3]."'>";
			$data.="<label class='control-label' for='".$caption[3]."'>".$caption[0]."</label>";
			$data.="<div class='controls'>";
			$data.=$this->field."";
			$data.="</div><div class='controls'></div></div>";
		}
		return $data;
	}
	
	function frm_gabungan()
	{
		$data='<hr>';
		$this->action_col(true);
		$this->tabel_content($this->frmInline('',false,false,false,false));
		$data.=$this->list_std('NewList','90%',false);
		return $data;
	}
	function frmInline($idfrm='frm01',$parator=false,$buton=true,$Titel=false,$frm=true)
	{
		$row=$this->Count(($frm==true)?$this->sec:$this->sec2,$this->path);	
		$data=($frm==true)?"<form class='form-inline' role='form' id='".$idfrm."'>":'';
		$data.=($frm==false)?"<tfoot><tr class=''>":"";
		for($i=1;$i<=$row;$i++)
		{
			$data.=($frm==false)?"<td align='center' style='border:1px solid #999; ' valign='top'>":"";
			$rContent=$this->rContent(($frm==true)?$this->sec:$this->sec2,$i,$this->path);
			$fld=explode(',',$rContent);
			$data.=($fld[1]=='button' || $fld[1]=='btn' || $fld[0]=='')?'':"<label class='control-label' for='".$fld[3]."'>".$fld[0]."</label>".nbs(2);
			switch($fld[1])
			{
				case "input":
				$data.=($fld[2]=='search')?
					"<div class='input-append'>
					 <input type='".$fld[2]."' class='".$fld[5]."' name='".$fld[3]."' id='".$fld[3]."' placeholder='".$fld[4]."' value='".$fld[6]."'>
					 <button class='btn' type='button' id='c_".$fld[3]."'>GO</button></div>".nbs(5):
					"<input type='".$fld[2]."' class='".$fld[5]."' name='".$fld[3]."' id='".$fld[3]."' placeholder='".$fld[4]."' value='".$fld[6]."'>".nbs(5);
				break;
				case "select":
				$data.="<select class='".$fld[5]."' name='".$fld[3]."' id='".$fld[3]."'>";
				if (!empty($fld[7]))
				{
					if($fld[7]=='RS')
					{
					$data.= "<option></option>";
						for ($x=1;$x<=$this->Count($fld[8],$this->path);$x++)
						{
							$datax=explode(",",$this->rContent($fld[8],$x,$this->path));
							$data.= "<option value='".$datax[0]."'>".$datax[1]."</option>";
						}
					}
				}
				$data.="</select>".nbs(5);
				break;
				case "textarea":
				$data.="<textarea class='".$fld[5]."' name='".$fld[3]."' id='".$fld[3]."'></textarea>".nbs(5);
				break;
				case "button":
				$data.=($buton==false)?'':"<button type='".$fld[2]."' class='".$fld[5]."' name='".$fld[3]."' id='".$fld[3]."'>".$fld[0]."</button>".nbs(5);
				break;
				case "btn":
				$data.=($buton==false)?"<button type='".$fld[2]."' id='".$fld[3]."' class='btn' >".$fld[0]."</button>".nbs(5):'';
				break;
				
			}
			$data.=($frm==false)?"</td>":"";
		}
		$data.=($frm==false)?
				"<td align='center' valign='middle' >
				<button type='button' class='btn' onclick=\"btn_click('simpan','simpan');\">
				<i class='cus-disk'></i></button></td></tr></tfoot>":"";
		$data.=($Titel==true)?"<span id='txt' name='txt'></span>":"";
		$data.=($frm==true)?"</form>":'';
		$data.=($parator==true)?"<hr/>":'';
		return $data;
  	}
	//generate standard button
	function buttons($show=false,$caption='Save',$type='button',$id='')
	{
    	$data='';
		$data="<div class='form-actions'>";
    	$data.=(seriale()=="Demo")?"":"<button type='".$type."' class='btn btn-primary' id='b_".str_replace(' ','_',$caption).$id."'><i class='cus-disk'></i> ".$caption."</button>";
    	$data.=empty($this->AddButton)?'':$this->AddButton;
		$data.=nbs(2)."<button type='reset' class='btn' id='d_".str_replace(' ','_',$caption).$id."'><i class='cus-delete'></i> Cancel</button>";
    	$data.="<span id='rst'></span></div>";
		return($show==true)? $this->button=$data:$this->button='';
	}
	//generate field input,textarea,select
	function addButtons($show=false,$caption='Preview',$img='cus-printer')
	{
    	$data='';$n=0;
		$data="<div class='form-actions'>";
		if(is_array($caption))
		{
			foreach ($caption as $d)
			{
				$pm=($n==0)?"btn-primary":"";
				$data.="<button type='button' class='btn $pm ' id='b_".str_replace(' ','_',$d)."'><i class='".$img[$n]."'></i> ".$d."</button>";
				$n++;
			}
		}else{
			$data.="<button type='button' class='btn btn-primary' id='b_".str_replace(' ','_',$caption)."'><i class='".$img."'></i> ".$caption."</button>";
		}
		$data.="<button type='button' class='btn' id='d_".str_replace(' ','_',$caption)."'><i class='cus-cross'></i> Cancel</button>";
    	$data.="<span id='rst'></span></div>";
		return($show==true)? $this->buttone=$data:$this->buttone='';
	}
	function field_type($field)
	{
		$fld=explode(',',$field);
		$plc=($fld[4]=='')?$fld[0]:$fld[4];
		switch ($fld[1])
		{
			case 'input':
			if(!empty($fld[7]))
			{
			$tph=empty($this->typeahead)?'':$this->typeahead;
			$text=($fld[7]=='TP')?"<input type='".$fld[2]."' id='".$fld[3]."' name='".$fld[3]."' class='".$fld[5]."' placeholder='".$plc."' value='".$fld[6]."' data-source=\"[".$tph."]\"/>":
				"<input type='".$fld[2]."' id='".$fld[3]."' name='".$fld[3]."' class='".$fld[5]."' placeholder='".$plc."' value='".$fld[6]."'/>";
			}else{
			$text="<input type='".$fld[2]."' id='".$fld[3]."' name='".$fld[3]."' class='".$fld[5]."' placeholder='".$plc."' value='".$fld[6]."'/>";
			}
			break;
			case 'select':
			if($fld[6]=='')
			{
				$text="<select id='".$fld[3]."' name='".$fld[3]."' class='".$fld[5]."'>";
				//dropdown content
				if (!empty($fld[7]))
				{
				if($fld[7]=='RS')
					{
					$text.= "<option></option>";
						for ($x=1;$x<=$this->Count($fld[8],$this->path);$x++)
						{
							$data=explode(",",$this->rContent($fld[8],$x,$this->path));
							$text.= "<option value='".$data[0]."'>".$data[1]."</option>";
						}
					}else if($fld[7]=='RD'){
						//$data=explode("-",$fld[8]);
						$text.= $this->option;
						//dropdown($data[0],$data[1],$data[2],$data[3]);
					}
				}
				$text.="</select>";
			}else{
			$text=($fld[6]!='')?"<div class='input-append'>
					<select class='span2' id='".$fld[3]."' name='".$fld[3]."'>".$this->option."</select>
					<button class='btn' type='button' id='p-".$fld[3]."'><i class='".$fld[4]."'></i> ".$fld[6]."</button>
					</div>":'';
			}
			break;
			case 'textarea':
			$text="<textarea rows='2' id='".$fld[3]."' name='".$fld[3]."' class='".$fld[5]."' placeholder='".$plc."'></textarea>";	
			break;
		}
		return $this->field=$text;
	}
	function tp_ahead($tphead='')
	{
		return $this->typeahead=$tphead;	
	}
	function get_select_opt($data='')
	{
		return $this->option=$data;
		//return $id;
	}
	function get_select_id($id='')
	{
		return $this->idne=$id;	
	}
	/**
		generate table list
		with caption field get from file frm
	*/
	
	function list_std($id='NewList',$width='100%',$frm=true)
	{
		$row=$this->Count(($frm==true)?$this->sec:$this->sec3,$this->path);
		$data=tabel('table table-bordered table-hover',$width,$id);
		$data.=tr('alert alert-info',true,'center');
		for($i=1;$i<=$row;$i++)
		{
			$content=explode(',',$this->rContent(($frm==true)?$this->sec:$this->sec3,$i,$this->path));
			$data.=td($content[0],$content[1],$content[2],$content[3],$content[4],(count($content)>=6)?$content[5]:'');
		}
		$data.=$this->aksi;
		$data.=_tr(true);
		$data.=($frm==true)?$this->list_content:'';
		$data.=tContent(true);
		$data.=($frm==false)?$this->list_content:'';
		$data.=_tabel();
		return $data;
	}
	/**
		generate grid list with div or span
	*/
	function list_grid($id='NewList',$width='100%')
	{
		$data="<div class='xx'>";
		$row=$this->Count($this->sec,$this->path);
		for($i=1;$i<=$row;$i++)
		{
			$content=explode(',',$this->rContent($this->sec,$i,$this->path));
			$data.=div($content[0],$content[3],$content[4]);
		}
		$data.="</div>";
		return $data;
	}
	
	function tabel_content($datax)
	{
		return $this->list_content=$datax;	
	}
	
	function DataNotFound($data,$col_count=1)
	{
		if(empty($data))
		{
			return tr().td("<i class='cus-exclamation'></i> Data not found...",'',false,'left\' colspan=\''.$col_count.'');
		}
	}
	function action_col($action=false,$label='')
	{
		$data= ($action==true)?	td($label,'5%',true):'';
		return $this->aksi=$data;
	}
	
	/**
	generate menu bar with two level 
	header menu--------------------------------------------
	*/
	function menu_bar($mnu='mainmenu')
	{
		$this->section($mnu);$data='';
		$row=$this->Count($this->sec,$this->path);
		for($i=1;$i<=$row;$i++)
		{
			$fld=explode(',',$this->rContent($this->sec,$i,$this->path));
			$this->sub_menus($fld[0]);
			if($fld[5]=='dropdown')
			{
				$data.="<li class='dropdown'><a href='#' class='dropdown-toggle' data-toggle='dropdown'><i class='".$fld[4]."'></i> ".$fld[0]."<b class='caret'></b></a>";
				$data.=$this->sub_menu;
				$data.="</li>";
			}else if($fld[5]=='about'){
			
				$data.="<li class='' style='cursor:pointer' id='about'><a href='' onclick=\"js:return false;\"><i class='".$fld[4]."'></i> ".$fld[0]."</a></li>";	
			}else{
				if($this->CI->session->userdata('login'))
				{
					if($fld[0]!='Sign In')
					{
						$data.="<li class='".$fld[5]."'><a href='".base_url()."index.php/".$fld[1]."' id='".strtolower(str_replace(' ','',$fld[0]))."'><i class='".$fld[4]."'></i> ".$fld[0]."</a></li>";	
					}
				}else{
					if($fld[0]!='Sign Out')
					{
						$data.="<li class='".$fld[5]."'><a href='".base_url()."index.php/".$fld[1]."' id='".strtolower(str_replace(' ','',$fld[0]))."'><i class='".$fld[4]."'></i> ".$fld[0]."</a></li>";	
					}
				}
			 
			}
			
		}
		
	 return $data;
	}
	
	//generate sub_menu (level 1) ------------------------------------------
	function sub_menus($mnu)
	{
				$jml=0;
				//$this->section($mnu);
				$jml=$this->Count($mnu,$this->path);
				$data="<ul class='dropdown-menu'>";
					for($x=1;$x<=$jml;$x++)
					{
						$submn=explode(',',$this->rContent($mnu,$x,$this->path));
						$data.="<li class='".$submn[5]."'><a href='".base_url()."index.php/".$submn[1]."'><i class='".$submn[4]."'></i> ".$submn[0]."</a></li>";	
					}
				$data.="</ul>";
		return $this->sub_menu=$data;	
	}

	function menu_dashboard()
	{

		$jml=0;$data='';
		$this->section('menudashboard');
		$jml=$this->Count($this->sec,$this->path);
		for($i=1;$i<=$jml;$i++)
		{
			$mn=explode(',',$this->rContent($this->sec,$i,$this->path));
			$data .="<div id='mnu' class='span2' onclick=\"_go_to('".base64_encode($mn[0])."');\"><img id='xx' src='".base_url()."asset/img/".$mn[3]."' class='img-rounded' alt='".$mn[0]."'/></div>";

		}
		return $this->menu_dashboard=$data;
	}
	function menu_shortcut()
	{

		$jml=0;$data='';
		$this->section('menudashboard');
		$jml=$this->Count($this->sec,$this->path);
		for($i=1;$i<=$jml;$i++)
		{
			$mn=explode(',',$this->rContent($this->sec,$i,$this->path));
			$data .="<div id='mnu' class='' onclick=\"_go_to('".base64_encode($mn[0])."');\"><img id='xx' src='".base_url()."asset/img/".$mn[3]."' class='img-rounded' alt='".$mn[0]."'/></div>";

		}
		return $this->menu_shortcut=$data;
	}
	//----end of generate menu
	
	//generate tab header via zetro-menu.frm file
	function tab_header($addTab=false)
	{
		$row=0;
		$row=$this->Count($this->sec,$this->path);
		$data="<ul class='nav nav-tabs'>";
		for($i=1;$i<=$row;$i++)
		{
			$tab=explode(',',$this->rContent($this->sec,$i,$this->path));	
			$data.="<li class='".$tab[4]."' id='t-".$tab[1]."'><a href='#".$tab[1]."' data-toggle='tab' id='p-".$tab[1]."'><i class='".$tab[5]."'></i> ".$tab[0]."</a></li>";	
		}
		if($addTab==true)
		{
			$data.="<li class='pull-right'>";
			$data.=$this->filter;
			$data.="<li>";
		}
		$data.="</ul>";
		return $data;
	}
	
	function AddFilter($filter)
	{
		return $this->filter=$filter;
	}
	function AddUb($unit_bis)
	{
		return $this->unit_bis=$unit_bis;	
	}
	function fld($fld,$txt=false)
	{
			$data="<form id='frm100' name='frm100'>";
			$data.=($txt==false)?'':"<span class='' id='txt' name='txt'>".$txt."</span>".nbs(5);
			$data.="<div class='input-prepend pull-right'>";
			$data.=$fld;
			$data.="</div></form>";
			return $data;
	}
	function FilterBlnThn($bln='Bulan',$thn='Tahun',$addFlt=false)	
	{
			$data="<form id='frm100' name='frm100'>";
			$data.="<div class='input-prepend pull-right'>";
			$data.=($addFlt==true)?$this->unit_bis:"";
			$data.="<span class='add-on'>$bln</span>
            		<select class='span1koma5' id='bulan' name='bulan'>".dropdownBln(date('m'))."</select>
           			<span class='add-on'>$thn</span>
            		<select class='span1' id='tahun' name='tahun'></select>
       				</div>";
			$data.="</form>";
			return $data;
	}
	
	function FilterTgl($upto=false,$addP=false,$kdr='akun',$bln='Dari Tanggal',$thn='Sampai')
	{
			$data="<form id='frm100' name='frm100' class='navbar-form'>";
			$data.="<div class='input-prepend pull-right'>";
			$data.=($kdr=='akun')?"<span class='add-on'>Kode Akun</span>
            <input type='text' class='span3' id='kodrek' name='kodrek' value='' placeholder='Kode Rekening'>":$this->unit_bis;
			$data.=($upto==true)?
					"<span class='add-on'>$bln</span>
					<input type='text' class='span1koma5' id='from_tgl' name='from_tgl' value='' placeholder='$bln'>".nbs(2)."
					<span class='add-on'>$thn</span>
					<input type='text' class='span1koma5' id='upto_tgl' name='upto_tgl' value='' placeholder='$thn'>&nbsp;&nbsp;":
					"<span class='add-on'>$bln</span>
					<input type='text' class='span1koma5' id='from_tgl' name='from_tgl' value='' placeholder='$bln'>&nbsp;&nbsp;";
       		$data.="<button type='button' id='ok' class='btn'><i class='cus-tick'></i> OK</button>";
			$data.=($addP==true)?"<button type='button' id='print' class='btn'><i class='cus-printer'></i> Preview</button>":'';
			$data.="</div>";
			$data.="</form>";
			return $data;
	}
	function FilterKodeRek($kd="Kode Rekening")
	{
		$data="<div class='input-prepend'>";
		return $data;
	}
	//generate tab for second tab
	function nav_pill()
	{
		$row=0;
		$row=$this->Count($this->sec,$this->path);
		$data="<ul class='nav nav-tabs'>";
		for($i=1;$i<=$row;$i++)
		{
			$tab=explode(',',$this->rContent($this->sec,$i,$this->path));	
			if($tab[2]=='y'){
				$data.="<li class='".$tab[6]."' ><a href='#tab".$i."' data-toggle='tab'  onClick=\"get_list('".str_replace(' ','_',$tab[0])."');\" id='t-tab".$i."'><i class='".$tab[4]."'></i> ".$tab[0]."</a></li>";
			}
		}
		$data.="</ul>";	
		return $data;
	}
	
	//generate authorisation list check box
/*	function menus($menu)
	{
		$this->menu=$menu;	
	}
*/
	function list_menu($mnu='admin')
	{
		
		$row=0;$data='';$dsbl='';
		$this->frm_file('asset/frm/zetro_menu.frm');
		$row=$this->Count($mnu,$this->path);$n=0;
		$this->CI->zetro_auth->menus('authorization');
		$dsbl=($this->CI->zetro_auth->cek_oto('c')=='')?'disabled':'';
		for($i=1;$i<=$row;$i++)
		{
			$jml=0;
			$tab=explode(',',$this->rContent($mnu,$i,$this->path));
			$jml=$this->Count($tab[0],$this->path);
			if($tab[2]=='y')//jika satusnya y alias ditampilkan
			{
				if($jml==0) //jika tidak punya sub menu
				{
					$n++;
					$this->CI->zetro_auth->menus(strtolower(str_replace(' ','_',$tab[0])));
					$idCK=strtolower(str_replace(' ','_',$tab[0]));
					$data.=tr().td($n,'',false,'','center').td($tab[0]).
						   td("<input $dsbl type='checkbox' ".$this->stat_oto('c')." id='c-".$idCK."' ".$this->un_required($tab[3],'c')." onclick=\"aksi('c','".strtolower(str_replace(' ','_',$tab[0]))."');\">",'',false,'','center').	
						   td("<input $dsbl type='checkbox' ".$this->stat_oto('e')." id='e-".$idCK."' ".$this->un_required($tab[3],'e')." onclick=\"aksi('e','".strtolower(str_replace(' ','_',$tab[0]))."');\">",'',false,'','center').	
						   td("<input $dsbl type='checkbox' ".$this->stat_oto('v')." id='v-".$idCK."' ".$this->un_required($tab[3],'v')." onclick=\"aksi('v','".strtolower(str_replace(' ','_',$tab[0]))."');\">",'',false,'','center').
						  _tr();
				}else{
					$n++;
					$data.=tr('alert alert-info').td($n,'',false,'','center').td($tab[0],'left\' colspan=\'4')._tr();
					for($x=1;$x<=$jml;$x++)
					{
						$jml_lagi=0;$z=0;
						$subtab=explode(',',$this->rContent($tab[0],$x,$this->path));
						$this->CI->zetro_auth->menus(strtolower(str_replace(' ','_',$subtab[0])));
						$idCKs=strtolower(str_replace(' ','_',$subtab[0]));
						$jml_lagi=$this->Count($subtab[0],$this->path);
						if($subtab[2]=='y')
						{
							
							if($jml_lagi==0)
							{
							$z++;
							$data.=tr().td('','center').td("<i class='cus-bullet-red'></i> ".$subtab[0]).
								   td("<input $dsbl type='checkbox' ".$this->stat_oto('c')." id='c-".$idCKs."' ".$this->un_required($subtab[3],'c')." onclick=\"aksi('c','".strtolower(str_replace(' ','_',$subtab[0]))."');\">",'',false,'','center').	
								   td("<input $dsbl type='checkbox' ".$this->stat_oto('e')." id='e-".$idCKs."' ".$this->un_required($subtab[3],'e')." onclick=\"aksi('e','".strtolower(str_replace(' ','_',$subtab[0]))."');\">",'',false,'','center').	
								   td("<input $dsbl type='checkbox' ".$this->stat_oto('v')." id='v-".$idCKs."' ".$this->un_required($subtab[3],'v')." onclick=\"aksi('v','".strtolower(str_replace(' ','_',$subtab[0]))."');\">",'',false,'','center').
								  _tr();
							}else{
							$z++;
							$data.=tr('alert alert-error').td('','',false,'','center').td("<i class='cus-bullet-red'></i> ".$subtab[0],'left\' colspan=\'4')._tr();	
								for($xx=1;$xx<=$jml_lagi;$xx++)
								{
									$subsubtab=explode(',',$this->rContent($subtab[0],$xx,$this->path));
									$this->CI->zetro_auth->menus(strtolower(str_replace(' ','_',$subsubtab[0])));
									$idCKsS=strtolower(str_replace(' ','_',$subsubtab[0]));
									if($subsubtab[2]=='y')
									{
									$data.=tr().td('','center').td(nbs(5)."<i class='cus-bullet-green'></i> ".$subsubtab[0]).
										   td("<input $dsbl type='checkbox' ".$this->stat_oto('c')." id='c-".$idCKsS."' ".$this->un_required($subsubtab[3],'c')." onclick=\"aksi('c','".strtolower(str_replace(' ','_',$subsubtab[0]))."');\">",'',false,'','center').	
										   td("<input $dsbl type='checkbox' ".$this->stat_oto('e')." id='e-".$idCKsS."' ".$this->un_required($subsubtab[3],'e')." onclick=\"aksi('e','".strtolower(str_replace(' ','_',$subsubtab[0]))."');\">",'',false,'','center').	
										   td("<input $dsbl type='checkbox' ".$this->stat_oto('v')." id='v-".$idCKsS."' ".$this->un_required($subsubtab[3],'v')." onclick=\"aksi('v','".strtolower(str_replace(' ','_',$subsubtab[0]))."');\">",'',false,'','center').
										  _tr();
												
									}
								}
							}
						}
						
					}
				}
			}
		}
		
		return $data;
	}
	function un_required($idmenu,$field){
		$datax=false;
		$datax=strpos($idmenu,$field);
		return($datax==true)?'':" disabled='disabled'";
	}	

	//dropdown option content
	function generate_dropdown_content($table,$id_field,$nm_field,$where='',$select='',$id='')
	{
		$this->CI->main_model->table_name($table);
		$this->CI->main_model->where($where);
		$this->CI->main_model->dropdwn_select($select);
		$this->get_select_id($id);
		return $this->get_select_opt($this->CI->main_model->dropdown_data($id_field,$nm_field));
	}
	//create tab header form
	function generate_tab_header($section='',$addTab=false,$filename='asset/frm/zetro_menu.frm')
	{
		$this->frm_file($filename);
		$this->section($section);
		return $this->tab_header($addTab);
		//generate form
	}
	//check status otorisasi
	
	function stat_oto($field,$table='user_oto',$xx='')
	{
		$data=array();
		$this->CI->load->model('main_model');
		$this->CI->main_model->table_name($table);
		$this->CI->main_model->set_methods('select');
		$this->CI->main_model->query();
		($xx=='')?
		$this->CI->main_model->where(array('userid'=>$this->userid,'modul'=>$this->CI->zetro_auth->menu)):
		$this->CI->main_model->where(array('nm_menu'=>$this->CI->zetro_auth->menu));
		$data=$this->CI->main_model->set_data();
		$datax="";
		foreach($data as $r)
		{
			$datax=($r->$field=='Y')?"checked='checked'":'';
		}
		return $datax;	
	}
	
	function z_icon($id,$img='cus-page-white-edit',$aksi='edit')
	{
		if(is_array($aksi)){
			$data="<div class='btn-group'>";
			$n=0;
				foreach($aksi as $ide){
				$data.="<button type='button' class='btn btn-mini' onclick=\"btn_click('".$id."','".$ide."');\" title='".ucwords($aksi[$n])."'><i class='".$img[$n]."'></i></button>";
				$n++;
				}
			$data.="</div>";
		}else{
			$data="<button type='button' class='btn btn-mini' onclick=\"btn_click('".$id."','".$aksi."');\" title='".ucwords($aksi)."'><i class='".$img."'></i></button>";
		}
		return $data;
	}
	
	function dialog($data,$title,$id='',$footer=false,$height='',$printbtn=false,$idbtn='')
	{
		$xx='';
		$height=($height=='')?'':"style='height:".$height.";'";
		
		 $data="<!---Begin modal $id -->
		        <div id='myModal".$id."' class='modal hide fade' style='border:3px solid #999999'>
            	<div class='modal-header'>
              		<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>&times;</button>
              		<h4 id='myModalLabel' style='cursor:move'><i class='cus-cog'></i> ".$title."</h4>
            	</div>
             	<div class='modal-body' ".$height.">".$data.$xx."</div>";
		 if($footer==true){
		 	$data.="<div class='modal-footer'><span id='rst'></span>";
		 	$data.=($printbtn==true)?"<button class='btn btn-warning' id='add_t'>Print</button>":"";
			$data.="<button class='btn btn-primary' id='simpan".$idbtn."'>Simpan</button>
					<button class='btn' id='batal".$idbtn."' data-dismiss='modal'>Cancel</button>
				</div>";
		 }
          $data.="</div><!-- end of modal $id -->";
          $data.="<script language='javascript'>	$(document).ready(function(e){ $('#myModal".$id."').draggable({cursor:'move',handle:'h4'});})</script>";	 
	return $data;
	}
	
	function PrintPreview($title='Buku Besar')
	{
		 $data="<!---Begin modal $title -->
		        <div id='PrintPrev' class='modal hide fade' style='border:3px solid #999999'>
            	<div class='modal-header'>
              		<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>&times;</button>
              		<h4 id='myModalLabel'><i class='cus-cog'></i> ".$title."</h4>
            	</div>
             	<div class='modal-body'>
				<iframe id='prv' src='' height='100%' width='100%' frameborder='0' allowtransparency='1' style='z-index:100'></iframe>
				</div>";
          $data.="</div><!-- end of modal $title -->";
          $data.="<script language='javascript'>	$(document).ready(function(e){ $('#PrintPrev').draggable({cursor:'move',handle:'h4'});})</script>";	 
		return $data;
	}
	function AddFields($field='')
	{
		return $this->AddField=$field;
		
	}
	function Modale($id='')
	{
		return $this->dp_Modal=$id;
	}
	//modul List for approval setting
	function modul_app_seting()
	{
		$dsbl='';$main=0;$data='';
		$this->frm_file('asset/frm/zetro_menu.frm');
		$this->CI->zetro_auth->menus('modul_approval_setting');
		$dsbl=($this->CI->zetro_auth->cek_oto('c')=='')?'disabled':'';
		$main=$this->Count("menudashboard",$this->path); //get count of main section
		for ($z=1;$z<=$main;$z++)
		{
			$cn=0;
			$mn=explode(',',$this->rContent('menudashboard',$z,$this->path));
			$row=0;
			$data.=tr('alert alert-error').td('<b>'.$mn[0].'</b>',false,'','','left\' colspan=\'3').
			$row=$this->Count($mn[0],$this->path);$n=0;
			for($i=1;$i<=$row;$i++)
			{
				$jml=0;
				$tab=explode(',',$this->rContent($mn[0],$i,$this->path));
				$jml=$this->Count($tab[0],$this->path);
				if($tab[2]=='y')//jika satusnya y alias ditampilkan
				{
					if($jml==0) //jika tidak punya sub menu
					{
						$n++;
						$this->CI->zetro_auth->menus(strtolower(str_replace(' ','_',$tab[0])));
						$idCK=strtolower(str_replace(' ','_',$tab[0]));
						$data.=tr().td($n,false,'','','center').td($tab[0]).
							   td("<input $dsbl type='checkbox' ".$this->stat_oto('c','modul_approval','x')." id='c-".$idCK."' onclick=\"aksi('c','".strtolower(str_replace(' ','_',$tab[0]))."');\">",'',false,'','center').	
							  _tr();
					}else{
						$n++;
						$data.=tr('alert alert-info').td($n,false,'','','center').td($tab[0],'left\' colspan=\'3')._tr();
						for($x=1;$x<=$jml;$x++)
						{
						$subtab=explode(',',$this->rContent($tab[0],$x,$this->path));
						$this->CI->zetro_auth->menus(strtolower(str_replace(' ','_',$subtab[0])));
						$idCKs=strtolower(str_replace(' ','_',$subtab[0]));
							if($subtab[2]=='y')
							{
							$data.=tr().td('','center').td("<i class='cus-bullet-red'></i> ".$subtab[0]).
								   td("<input $dsbl type='checkbox' ".$this->stat_oto('c','modul_approval','x')." id='c-".$idCKs."' onclick=\"aksi('c','".strtolower(str_replace(' ','_',$subtab[0]))."');\">",'',false,'','center').	
								  _tr();
							}
						}
					}
				}
			}
		}
		return $data;
	}
	function notifikator($data='',$title='')
	{
		$ttl=($title=='')?"New Register from web\n please click for process this data":$title;
		echo "<span class='badge badge-warning' id='Online' title='".
			  $ttl."' style='cursor:pointer;display:none'>".$data."</span>";
	}
	function notifycator($notify='')
	{
		$this->notify=$notify;	
	}
	function infoCo($fld='Nama')
	{
		return base64_decode($this->rContent('company',$fld,'asset/frm/zetro_config.dll'));
	}
	//
//end of zetro_form class
//location : application/libraries
}
?>
